import java.util.Scanner;

public class NGuessNumber {
    public static void main(String[] args) {
        int[] Answer;
        int i = 0;
        NGuessNumber ng = new NGuessNumber();
        Answer = ng.generateAnswer();
        Scanner sc = new Scanner(System.in);
        String restart;
        do{
            while (i < 3) {
                int[] pi = ng.getPlayerInput();
                int count = ng.compareGuessAnswer(Answer, pi);
                boolean isWin = ng.isWin(count);
                if (isWin) {
                    System.out.println("猜对了");
                    break;
                } else {
                    System.out.println("猜错了");
                }
                i++;
            }

            System.out.println("是否再猜一次？输入“n”结束游戏，其他为继续");
            restart = sc.next();
        }while (!restart.equals("n"));
        System.out.println("结束了");
    }

    int[] generateAnswer(){
        int[] arr = new int[4];
        int[] temp = {0,1,2,3,4,5,6,7,8,9};
        for (int i = 0;i< arr.length;i++){
            int tempIndex = (int)(Math.random()*10);
            if (temp[tempIndex]==99){
                i--;
            }else {
                arr[i]= temp[tempIndex];
                temp[tempIndex]=99;
            }
        }

        return arr;
    }

    int[] getPlayerInput(){
        int[] arr = new int[4];
        Scanner sc = new Scanner(System.in);
        arr[0]=sc.nextInt();
        arr[1]=sc.nextInt();
        arr[2]=sc.nextInt();
        arr[3]=sc.nextInt();
        return arr;
    }

    int compareGuessAnswer(int[] randomGroup,int[] playerInput){
        int count=0;

        for (int i = 0; i < 4; i++) {
            if (randomGroup[i]==playerInput[i]){
                count++;
            }
        }

        return count;
    }

    boolean isWin(int count){
        return count == 4;
    }
}